﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;


namespace MvcApplicationYoung.WcfServiceLibrary
{
    public class NewInspector : System.ServiceModel.Dispatcher.IParameterInspector
    {
        public delegate void DelBeforeCall(string operationName,object[] inputs);
        public event DelBeforeCall evtBeforeCall;

        public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
        {
            Console.WriteLine(
              "IParameterInspector.AfterCall called for {0} with return value {1}.",
              operationName,
              returnValue.ToString()
            );
        }

        public object BeforeCall(string operationName, object[] inputs)
        {
            if (evtBeforeCall != null)
            {
                evtBeforeCall.Invoke(operationName,inputs);
            }
            return null;
        }
   
    }

    public class OwnBehavior1:IOperationBehavior 
    {
        NewInspector nInspector;

        public OwnBehavior1()
        {
            nInspector = new NewInspector();
        }

        public NewInspector NInspector
        {
            get { return nInspector; }
        
        }

        public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        { return; }

        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {

        }

        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            
            dispatchOperation.ParameterInspectors.Add(nInspector);
        }

        public void Validate(OperationDescription operationDescription) { return; }

    }
}